export default class Pagination {
  currentPage = 1;
  totalCount = 0;
  pageSize = 10;

  constructor(pageSize) {
    if (pageSize !== undefined) {
      this.pageSize = pageSize;
    }
  }

  getTotalPage() {
    let totalPage = Math.ceil(this.totalCount / this.pageSize);
    return totalPage;
  }

  nextPage() {
    let page = this.currentPage;
    let totalPage = this.getTotalPage();
    page++;
    if (page > totalPage) {
      page = totalPage;
    }
    this.currentPage = page;
  }

  hasNextPage(){
    let totalPage = this.getTotalPage();
    let currentPage = this.currentPage;
    return currentPage < totalPage;
  }

  getObject() {
    return {
      limit: this.pageSize,
      page: this.currentPage
    };
  }
}
